package pers.cnzdy.tutorial.Chapter5_UI.Section7_ListView;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import java.util.List;

import pers.cnzdy.tutorial.R;

public class QuizTypesActivity extends AppCompatActivity {
    private String[] data = { "选择题", "判断题", "填空题", "简答题", "计算题", "改错题", "程序题" };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        TestListView();
        //TestCustomListView();
    }

    public void TestListView() {
        setContentView(R.layout.activity_quiz_type_list);

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(
                QuizTypesActivity.this, android.R.layout.simple_list_item_1, data);
        ListView listView = findViewById(R.id.list_view);
        listView.setAdapter(adapter);
    }

    public void TestCustomListView() {
        setContentView(R.layout.activity_quiz_type_custom_list);

        QuizTypes                quizTypes;
        final List<QuizTypes.QuizType> quizTypeList;

        quizTypes = new QuizTypes();
        quizTypeList = quizTypes.getQuizTypeList();

        QuizTypesAdapter adapter = new QuizTypesAdapter(QuizTypesActivity.this,
                R.layout.quiz_type_item, quizTypeList);

        ListView listView = findViewById(R.id.quiz_custom_list_view);
        listView.setAdapter(adapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                QuizTypes.QuizType quizType = quizTypeList.get(position);
                Toast.makeText(QuizTypesActivity.this, quizType.getType(), Toast.LENGTH_SHORT).show();
            }
        });
    }
}
